perm filename CLTTST.TEX[B2,JMC]1 blob sn#763038 filedate 1984-07-20 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00006 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	% use this file for experimental typsetting using th `boo' macros
C00003 00003	% test material goes here
C00008 00004	\end{document}
C00009 00005	% anything can go here as tex won't read beyond the \end{document}
C00010 00006	%begindefun examples
C00015 ENDMK
C⊗;
% use this file for experimental typsetting using th `boo' macros

%  \pagelayout{boo}
\input{boo.plo[b2,jmc]}
%  \documentstyle{boo,boo11}
\input{boo.sty[b2,jmc]}
\input{boo11.sty[b2,jmc]}

\input boomac.new[b2,jmc]

\nofiles

\begin{document}

% test material goes here

\makeatletter  % to read macros with @

% macros for verbatim scanning
\def\ttverbatim{\begingroup
  \catcode`\\=\other
  \catcode`\{=\other
  \catcode`\}=\other
  \catcode`\$=\other
  \catcode`\&=\other
  \catcode`\#=\other
  \catcode`\%=\other
  \catcode`\~=\other
  \catcode`\/=\other
  \catcode`\_=\other
  \catcode`\↑=\other
\mathcode`\!="7021
\mathcode`\'="7027
\mathcode`\(="7028
\mathcode`\)="7029
\mathcode`\*="702A
\mathcode`\+="702B
\mathcode`\,="702C
\mathcode`\-="702D
\mathcode`\.="702E
\mathcode`\/="702F
\mathcode`\:="703A
\mathcode`\;="703B
\mathcode`\<="703C
\mathcode`\=="703D
\mathcode`\>="703E
\mathcode`\?="703F
\mathcode`\[="705B
\mathcode`\\="705C
\mathcode`\]="705D
\mathcode`\_="705F
\mathcode`\{="707B
\mathcode`\}="707D
  \obeyspaces \obeylines \tt}

\makeatother

|(A.B)|

|(A . B)|

$|(A . B)|$

$|(A.B)|$

\makeatletter  % to read macros with @

% macros for verbatim scanning
\def\ttverbatim{\begingroup
  \catcode`\\=\other
  \catcode`\{=\other
  \catcode`\}=\other
  \catcode`\$=\other
  \catcode`\&=\other
  \catcode`\#=\other
  \catcode`\%=\other
  \catcode`\~=\other
  \catcode`\/=\other
  \catcode`\_=\other
  \catcode`\↑=\other
  \mathcode`\.="702E
  \obeyspaces \obeylines \tt}

\makeatother

|(A.B)|

|(A . B)|

$|(A . B)|$

$|(A.B)|$


%  \mathcode`\!="5021
%  \mathcode`\'="8000 % ↑\prime
%  \mathcode`\(="4028
%  \mathcode`\)="5029
%  \mathcode`\*="2203 % \ast
%  \mathcode`\+="202B
%  \mathcode`\,="613B
%  \mathcode`\-="2200
%  \mathcode`\.="013A
%  \mathcode`\/="013D
%  \mathcode`\:="303A
%  \mathcode`\;="603B
%  \mathcode`\<="313C
%  \mathcode`\=="303D
%  \mathcode`\>="313E
%  \mathcode`\?="503F
%  \mathcode`\[="405B
%  \mathcode`\\="026E % \backslash
%  \mathcode`\]="505D
%  \mathcode`\_="8000 % \_
%  \mathcode`\{="4266
%  \mathcode`\}="5267
%  
\end{document}
% anything can go here as tex won't read beyond the \end{document}

%begindefun examples

We shall deal with the problem of reading the more general mixed list-dot notation
until a later chapter.
Here are the {\it read}  and {\it print}   programs
\begindefun{print}{}
(DEFUN PRINT (U) (PRINT1 U NIL))
\enddefun
%
\begindefun{print1}{}
(DEFUN PRINT1 (U L)
 (IF (ATOM U)
     (CONS U L)
     (CONS 'LP (PRINT1 (CAR U) (CONS 'DOT (PRINT1 (CDR U) (CONS 'RP L)))))))
\enddefun
For example \mkop{print}[{\sx (+ (* A B) C)}] is
{\sx (LP + DOT LP LP * DOT LP A DOT LP B DOT NIL RP RP RP DOT LP C DOT NIL RP RP RP)}.

\begindefun{read}{}
(DEFUN READ (U) (CAR (READ1 U)))
\enddefun

\begindefun{read1}{}
(DEFUN READ1 (U)
  (IF (ATOM U) 
      'READ-ERROR
  (IF (EQ (CAR U) 'LP)
      ((LAMBDA (W) (IF (OR (ATOM W) (NOT (EQ (CADR W) 'DOT)))
                       'READ-ERROR
                       ((LAMBDA (V) (IF (OR (ATOM V) (NOT (EQ (CADR V) 'RP)))
                                        'READ-ERROR
                                        (CONS (CONS (CAR W) (CAR V)) (CDDR V))))
                        (READ1 (CDDR W)))))
       (READ1 (CDR U)))
      U)))
\enddefun

A calculation will reveal that \mkop{read}[\mkop{print}[{\sx (+ (* A B) C)}]] is
{\sx (+ (* A B) C)}. The reader might care to see if \mkop{read} and \mkop{print}
are in fact inverses of one another, or at least think of the problems involved
in such a task.

A simplified version of the usual \lisp\ \mkop{eval} is the following:
\begindefun{eval}{}
(DEFUN EVAL (E A)
  (COND ((CONST? E)                E)
        ((VAR? E)                  (LOOKUP E A))
        ((QUOTE? E)                (ARG E))
        ((IF? E)                   (IF (EVAL (TEST E) A) (EVAL (THEN E) A) (EVAL (ELSE E) A)))
        ((LIST? E)                 (MAPCAR (FUNCTION (LAMBDA (X) (EVAL X A))) (BODY E)))
        ((CAR? E)                  (CAR (EVAL (ARG E) A)))
        ((CDR? E)                  (CDR (EVAL (ARG E) A)))
        ((CONS? E)                 (CONS (EVAL (1ST-ARG E) A) (EVAL (2ND-ARG E) A)))
        ((ATOM? E)                 (ATOM (EVAL (ARG E) A)))
        ((EQ? E)                   (EQ (EVAL (1ST-ARG E) A) (EVAL (2ND-ARG E) A)))
        ((ATOMIC-FUNCTION? E)      (EVAL (CONS (LOOKUP (FUN E) A) (BODY E)) A))
        ((LAMBDA? (FUN E))         (EVAL (LAMBDA-BODY E)
                                         (APPEND (PRUP (LAMBDA-VARS E)
                                                       (MAPCAR (FUNCTION (LAMBDA (X) (EVAL X A)))
                                                               (BODY E)))
                                                  A))) ) )
\enddefun
%
\begindefun{prup}{}
(DEFUN PRUP (X Y) 
   (IF (NULL X)
       NIL
       (CONS (CONS (CAR X) (CAR Y)) (PRUP (CDR X) (CDR Y)))))
\enddefun
%
\begindefun{test}{}
(DEFUN TEST (X) (CADR X))
(DEFUN THEN (X) (CADDR X))
(DEFUN ELSE (X) (CADDDR X))
                                                      
(DEFUN CONST? (X) (OR (NUMBERP X) (EQ X T) (EQ X NIL)))
                                                      
(DEFUN ATOM? (X) (EQ (CAR X) 'ATOM))
(DEFUN LAMBDA? (X) (EQ (CAR X) 'LAMBDA))
\enddefun